'use strict';

module.exports = app => {
  const { DataTypes, BIGINT, DATE } = app.Sequelize;

  const Topic = app.model.define('topic', {
    id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true },
    title: {
      type: DataTypes.STRING(30),
      allowNull: false,
    },
    description: {
      type: DataTypes.STRING(120),
      allowNull: false,
    },
    deleted: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0
    },
    pass: {
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0
    },
  }, {
    tableName: 't_topic'
  });
  Topic.associate = function () {
    app.model.Topic.belongsTo(app.model.Student, {
      foreignKey: 'stu_id',
      as: 'student'
    }),
      app.model.Topic.belongsTo(app.model.Teacher, {
        foreignKey: 'ins_id',
        as: 'teacher'
      })
  }


  return Topic;
};